package com.itheima.demo4.ZengDemo4;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

/**
 * @ClassName test4
 * @Author 16799
 * @Date 2025/9/29 21:19
 * @Version 1.0
 * @Description TODO
 **/
public class test4 {
    public static void main(String[] args) throws Exception {
        List<Integer> moneys = getMoneys();
        System.out.println(moneys);
        Collections.shuffle(moneys);
        System.out.println("----------打乱后------------");
        System.out.println(moneys);

        List<peopleThread> peopleThreads = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            peopleThread peopleThread = new peopleThread(moneys, i + "号");
            peopleThreads.add(peopleThread);
            peopleThread.start();
        }

        for (peopleThread peopleThread : peopleThreads) {
            peopleThread.join();
        }

        System.out.println("----------活动结束------");

        peopleThreads.stream().sorted((o1, o2) -> o2.getTotalMoney()-o1.getTotalMoney())
                .forEach(s->
                        System.out.println(s.getName()+"线程抢到的总红包： "+s.getTotalMoney()));

    }

    public static List<Integer> getMoneys() {
        List<Integer> moneys = new ArrayList<>();
        Random r = new Random();
        for (int i = 0; i < 160; i++) {
            moneys.add(r.nextInt(30)+1);
        }
        for (int i = 0; i < 40; i++) {
            moneys.add(r.nextInt(70)+31);
        }
        return moneys;
    }
}
